<template>
  <router-view/>
</template>

<script>
// This starter template is using Vue 3 experimental <script setup> SFCs
// Check out https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md
import { onMounted } from "vue";
import { useStore } from "vuex";

export default {
  components: {},
  setup() {
    const store = useStore();
    onMounted(() => {
      //在页面加载时读取sessionStorage里的状态信息
      if (sessionStorage.getItem("store")) {
        store.replaceState(Object.assign({}, store.state, JSON.parse(sessionStorage.getItem("store"))));
      }

      //在页面刷新时将vuex里的信息保存到sessionStorage里
      window.addEventListener("beforeunload", () => {
        sessionStorage.setItem("store", JSON.stringify(store.state));
      });
      let globalConfigData = {
        snapEnabled: false,
        autoSave: false
      };
      if (!localStorage.getItem("globalConfigData")) {
        localStorage.setItem("globalConfigData", JSON.stringify(globalConfigData));
      }
    });
    return {};
  }
};
</script>
